import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { Form, View, Textarea, Input, Button } from "@tarojs/components-rn";
import { observer, inject } from "@tarojs/mobx-rn";
import { getRuntime } from "../../utils/common";
import demandStyleSheet from "./demand_styles";
var _styleSheet = demandStyleSheet;

let Demand = class Demand extends Component {
  constructor() {
    super(...arguments);
    this.state = {
      publicationType: "1",
      description: '',
      contacts: '',
      phone: '',
      wechatNo: '',
      qqNo: '',
      address: '',
      loading: false,
      disabled: false,
      submitText: '立即发布'
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '发布需求' });
  }
  formSubmit(e) {
    const { homeStore } = this.props.stores;
    let { publicationType } = this.state;
    let { description, contacts, phone, wechatNo, qqNo, address } = e.detail.value;
    if (!description) {
      getRuntime().showToast('需求内容不能为空~');
      return;
    }
    if (!contacts) {
      getRuntime().showToast('联系人不能为空~');
      return;
    }
    if (!phone) {
      getRuntime().showToast('联系电话不能为空~');
      return;
    }
    this.setState({
      loading: true,
      disabled: true,
      submitText: '数据提交中...'
    });
    homeStore.saveUserInfomations({
      form: {
        publicationType, description, contacts, phone, wechatNo, qqNo, address
      },
      callBack: () => {
        this.setState({
          loading: false,
          disabled: false,
          submitText: '立即发布'
        });
        getRuntime().showToast('数据提交成功~');
        setTimeout(() => {
          getRuntime().navigateTo('/pages/newest/index');
        }, 2000);
      }
    });
  }
  inputChange(e) {
    let value = e.detail.value;
    let ind = 0;
    for (let i in value) {
      if (value.charAt(i) > 0) {
        ind = i;
        break;
      }
    }
    return value.substr(ind);
  }
  render() {
    let { description, contacts, phone, loading, disabled, submitText } = this.state;
    return <View style={_styleSheet["from-wrap"]}>
        <Form onSubmit={this.formSubmit.bind(this)}>
        <View style={_styleSheet["input-group"]}>
          <Textarea placeholderClass="placeholder-class" placeholder="请填写您要发布需求的具体内容(必填)" value={description} name="description" style={_styleSheet["from-textarea"]} />
        </View>
        <View style={_styleSheet["interval"]} />
        <View style={[_styleSheet["item-group"], _styleSheet["pt0"], _styleSheet["pb0"]]}>
          <View style={_styleSheet["input-group"]}>
            <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>联系人</View>
            <Input placeholder="请填写联系人姓名" placeholderClass="placeholder_class" name="contacts" value={contacts} style={_styleSheet["from-input"]} />
          </View>

          <View style={_styleSheet["input-group"]}>
            <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>联系电话</View>
            <Input placeholderClass="placeholder_class" placeholder="请填写联系电话" name="phone" value={phone} style={_styleSheet["from-input"]} />
          </View>

          <View style={[_styleSheet["input-group"], _styleSheet["input-switch"]]}>
            <View style={_styleSheet["input-name"]}>微信号</View>
            <Input placeholderClass="placeholder_class" placeholder="请填写微信号" name="wechatNo" style={_styleSheet["from-input"]} />
          </View>

          <View style={_styleSheet["input-group"]}>
            <View style={_styleSheet["input-name"]}>QQ号</View>
            <Input placeholderClass="placeholder_class" placeholder="请填写QQ号" name="qqNo" style={_styleSheet["from-input"]} />
          </View>

          <View style={_styleSheet["input-group"]}>
            <View style={_styleSheet["input-name"]}>联系地址</View>
            <Input placeholderClass="placeholder_class" placeholder="请填写联系地址" name="address" style={_styleSheet["from-input"]} />
          </View>
        </View>

        <Button formType="submit" type={"primary"} loading={loading} disabled={disabled} style={_styleSheet["from-submit"]}>{submitText}</Button>
        </Form>
      </View>;
  }
};
Demand = tslib_1.__decorate([inject("stores"), observer], Demand);
export default Demand;